package cn.cdzdjd.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import cn.cdzdjd.dao.UserSessionMapper;
import cn.cdzdjd.entity.UserSession;
import cn.cdzdjd.service.UserSessionService;
import lombok.AllArgsConstructor;

@Service
@AllArgsConstructor
public class UserSessionServiceImpl implements UserSessionService {
	private final UserSessionMapper userSessionMapper;

	@Transactional(rollbackFor = Exception.class)
	@Override
	public Long insert(UserSession user) {
		return (long) userSessionMapper.insert(user);
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public void update(UserSession user) {
		userSessionMapper.updateById(user);
	}

	@Override
	public UserSession findById(Long id) {

		return userSessionMapper.selectById(id);
	}

	@Override
	public UserSession findByOpenid(String openId) {
		LambdaQueryWrapper<UserSession> queryWrapper = Wrappers.<UserSession>lambdaQuery();
		queryWrapper.eq(UserSession::getOpenid, openId);
		return userSessionMapper.selectOne(queryWrapper);
	}
}
